import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { MessageService } from '../../core/service';

@Component({
  selector: 'app-banks-cards',
  templateUrl: './banks-cards.component.html',
  styleUrls: ['./banks-cards.component.scss']
})
export class BanksCardsComponent implements OnInit {
  isList:boolean = true;

  @Input()
  get bankList():Array<any> {
    return this._bankList;
  }
  set bankList(list: Array<any>) {
    if(list != undefined){
      if(list.length > 0 ){
        this.isList = true;
        list.map((item) => {
          item.isDefault=='Y'? this._beforSel = item : item;
          this.selEvent.emit(item);
        });
      }else{
        this.isList = false;
      };
      this._bankList = list;
    }
  };

  @Output()
  selEvent: EventEmitter<string> = new EventEmitter<string>();

  private _beforSel:any;
  private _bankList:Array<any>;

  constructor(
    private msg: MessageService
  ) { }

  ngOnInit() {
  };
  public change(e) {
    switch (e) {
      case 'newCard':
         this.selEvent.emit(e)
        break;
        default:
          this._beforSel? this._beforSel.isDefault = 'N' : this._beforSel = e;
          e.isDefault='Y';
          this._beforSel = e;
          this.selEvent.emit(e)
        break;
    }
  };
}
